package com.jiai.cloud.api;

import com.jiai.cloud.base.tools.RestResultGenerator;
import com.jiai.cloud.entity.TUser;
import com.jiai.cloud.feign.TUserAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/6/3.
 */
@RestController
@RequestMapping("/user")
public class TUserController {
    @Autowired
    private TUserAPI tUserAPI;
    //邮箱判断
    @RequestMapping( value = "/judgeUser" ,method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"})
    public  Object judgeUser(@RequestParam("email") String email){
        return tUserAPI.judgeUser(email);
    }
    //注册
    @RequestMapping(value = "/register",method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"})
    public Object register(TUser user){
        return tUserAPI.register(user);
    }
    //登录验证码验证
    @RequestMapping(value = "/templates" ,method=RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Object  login(@RequestParam("loginName")String loginName ,@RequestParam("password")String  password,@RequestParam("code") String code,HttpServletRequest request ){
        HttpSession session = request.getSession();
        String sessionCode = (String) session.getAttribute("code");
        if(!code.equalsIgnoreCase(sessionCode)){
          return  RestResultGenerator.genSuccessResult("验证码错误");
        }else {
            return  tUserAPI.login(loginName,password);
        }

    }

}
